import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import java.util.*;

import static com.sun.glass.ui.win.WinMenuItemDelegate.CommandIDManager.map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2024-11-19
 * Time:14:01
 */
public class Test {
    public static void main6(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            String s1 = in.nextLine();
            String s2 = in.nextLine();
            fun(s1, s2);
        }

    }

    public static void fun(String str1, String strAct) {
        Set<Character> set = new HashSet<>();
        for (char ch : strAct.toUpperCase().toCharArray()) {
            set.add(ch);
        }
        Set<Character> set2 = new HashSet<>();
        for (char ch : str1.toUpperCase().toCharArray()) {
            if (!set.contains(ch) && !set2.contains(ch)) {
                System.out.println(ch);
                set2.add(ch);
            }
        }
    }

    public static void main5(String[] args) {
        Person person = new Person("123");
        Person person1 = new Person("123");
        HashBack2<Person, String> hashBack2 = new HashBack2<>();
        hashBack2.put(person1, "wangyuan");
        System.out.println(hashBack2.get(person1));
    }

    public static void main4(String[] args) {
        HashBack hashBack = new HashBack();
        hashBack.put(1, 1);
        hashBack.put(2, 2);
        hashBack.put(3, 3);
        hashBack.put(4, 4);
        hashBack.put(12, 12);
        hashBack.put(23, 23);
        hashBack.put(34, 34);
        hashBack.put(9, 9);
        System.out.println("========");
        System.out.println(hashBack.get(2));
    }

    public static void main3(String[] args) {
        Set<String> set = new TreeSet<>();
        set.add("hello");
        set.add("dog");
        set.add("yuan");
        System.out.println(set);
        for (String S : set) {
            System.out.println(S);
        }
    }

    public static void main2(String[] args) {
        Map<String, Integer> map = new TreeMap<>();
        TreeMap<String, Integer> map1 = new TreeMap<>();
        map1.put("this", 1);//根据key比较，设置key对应的Val
        map1.put("the", 6);
        map1.put("tbu", 9);
        map1.put("a", 9);
        map1.put("a", 344);


        /*int val=map1.get("the");//返回key对应的val
        System.out.println(val);
        //返回key对应的val，若不存在，则返回默认值19999
        int val1=map1.getOrDefault("gdy",19999);
        System.out.println(val1);
*/
        Set<String> set = map1.keySet();//返回所有key的不重复集合
        System.out.println();

        Collection<Integer> collection = map1.values();//返回val的可重复集合
        Set<Map.Entry<String, Integer>> entries = map1.entrySet();//返回所有的k,v映射关系

        for (Map.Entry<String, Integer> entry : entries) {
            System.out.println("key: " + entry.getKey() + "val: " + entry.getValue());
        }

    }

    public static void main1(String[] args) {
        BinarySearchTree binarySearchTree = new BinarySearchTree();
        binarySearchTree.insert(3);
        binarySearchTree.insert(5);
        binarySearchTree.insert(6);
        binarySearchTree.insert(2);
        binarySearchTree.insert(8);

        binarySearchTree.remove(6);
        System.out.println();
    }

    //统计单词出现的次数
    public static void func(String[] words) {
        Map<String, Integer> map = new HashMap<>();
        for (String word : words) {
            if (map.get(word) == null) {
                map.put(word, 1);
            } else {
                int val = map.get(word);
                map.put(word, val + 1);
            }
        }
        System.out.println(map);
    }
    public static void main12(String[] args) {
        String[] words={"this","the","money","happy","happy","money"};
        func(words);
    }
//前k个高频单词
    public List<String> topKFrequent(String[] words, int k) {
        Map<String, Integer> map = new HashMap<>();
        for (String word : words) {
            if (map.get(word) == null) {
                map.put(word, 1);
            } else {
                int val = map.get(word);
                map.put(word, val + 1);
            }
        }
        //建立小根堆,指定比较的方式
        PriorityQueue<Map.Entry<String, Integer>> minHeap = new PriorityQueue<>
                (new Comparator<Map.Entry<String, Integer>>() {
                    @Override
                    public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                        if(o1.getValue().compareTo(o2.getValue())==0){
                            //按照字母顺序建立大根堆
                            return o2.getKey().compareTo(o1.getKey());
                        }
                        return o1.getValue() - o2.getValue();
                    }
                });
        //3.遍历map 调整优先级队列
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if (minHeap.size() < k) {
                minHeap.offer(entry);
            } else {
                Map.Entry<String, Integer> top = minHeap.peek();
                //如果当前频率相同
                if (top.getValue().equals(entry.getValue())) {
                    //字母顺序小的进来
                    if (top.getKey().compareTo(entry.getKey()) > 0) {
                        //出队
                        minHeap.poll();
                        minHeap.offer(entry);
                    }
                } else {
                    if (top.getValue().compareTo(entry.getValue()) < 0) {
                        //出队
                        minHeap.poll();
                        minHeap.offer(entry);
                    }
                }
            }
        }
        List<String> ret=new ArrayList<>();
        for (int i=0;i<k;i++){
            Map.Entry<String,Integer> top=minHeap.poll();
            ret.add(top.getKey());
        }
        Collections.reverse(ret);
        return ret;
    }

    public static void main15(String[] args) {
        int a=12;
        int b=13;
        int sum=a+b;
        int d= a>b?a:b;
        System.out.println(sum);
    }
    public static void main(String[] args){
        char[] ch=new char[]{'a','b','c'};
        String s1=new String(ch);//s1对象并不在常量池中
        s1.intern();//调用之后，会将s1对象的引用放入常量池中
        String s2="abc";//再常量池中存在了，s2创建时直接用常量池中"abc"的引用
        System.out.println(s1==s2);
    }
//合并两个数组
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int end1=m-1;
        int end2=n-1;
        int index=m+n-1;//num1最后一个下标的位置
        //从最后一个入
        while(end1>=0&&end2>=0){
            if(nums1[end1]>nums2[end2]){
                nums1[index--]=nums1[end1--];
            }else{
                nums1[index--]=nums2[end2--];
            }
        }
        //nums2可能没有搬完
        while(end2>=0){
            nums1[index--]=nums2[end2--];
        }
    }
}
